var modifyOrAddFlag;

$(document).ready(
		function() {
			//所属领域下拉框
			$('#comboxfieldName').combobox({
				url: BASE_URL_FIELD_SEARCH + '/findAllOfCurrentUserCanManage' + '?v=' + Math.random(),
				valueField: 'id',
			    textField: 'name',
			    editable: false,
			    method:'get',
			    loadFilter: function(data){
			    	var allCheck = {'id':'','name':'全部'};
			    	data.content.unshift(allCheck);
			    	return data.content;
			    },
			    onSelect: function(record){
					
					if(record.id !== '')
					{
						comboxSearchSystemName.combobox({
						  disabled: false,
						  method:'get',
						  queryParams: {fieldId: record.id},
						  url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findByFieldOfCurrentUserCanManage' + '?v=' + Math.random(),
						  valueField: 'id',
						  textField: 'name',
						  data:'',
						loadFilter: function(data){
							var allCheck = {'id':'','name':'全部'};
							data.content.unshift(allCheck);
							return data.content;
						},
						onLoadSuccess:function(){
							comboxSearchSystemName.combobox('setValue','');
						}
					  }).load();
					}else
					{
						comboxSearchSystemName.combobox({
						  disabled: true,
						  editable: false				  
						});
					}
			    },
			    onLoadSuccess:function(){
			    	$('#comboxSystemName').combobox('setValue','');
			    }
			});
			
			//所属系统下拉框
			var comboxSearchSystemName = $('#comboxSystemName').combobox({
	          disabled: true,
	          valueField: 'id',
	          textField: 'name',
	          editable: false,
			  data:[{id:'',name:'全部','selected':'true'}]
	      });

			$("#datagrid").datagrid(
					{
						url : '/api/serviceLogTraces/search/findByExample?v='+ Math.random(),
						method : 'get',
						autoRowHeight : true,
						singleSelect : true,
						striped : true,
						nowrap : false,
						pageSize : 20,
						pageList : [ 10, 20, 50, 100 ],
						columns : [ [ {
							field : 'fieldName',
							title : '领域',
							width : 30,
							align : 'center'
						}, {
							field : 'systemName',
							title : '系统',
							width : 30,
							align : 'center'
						}, {
							field : 'interfaceName',
							title : '接口名称',
							width : 30							
						}, {
							field : 'createdDate',
							title : '生成时间',
							width : 25							
						},{
							field : 'message',
							title : '跟踪日志信息',
							width : 65,
							align : 'center',
						}]],
						pagination : true,
						onSelect : function(rowIndex, rowData) {
						},
						onUnselect : function() {
						},
						loadFilter : function(data) {	
							// alert("inData:"
							// + JSON.stringify(data));
							return {
								total : data.totalElements,
								rows : data.content
							};
						},
						onBeforeLoad : function(param) {
							param.page -= 1;
							param.size = param.rows;
							delete param.rows;

							param.sort = 'desc';
							
							var interfaceName = $('#txtIfName').val();
							if (interfaceName != "") {
								param.interfaceName = interfaceName;
							}
							
							var fieldName = $("#comboxfieldName").combobox("getValue");
							if(fieldName!=""){
								param.fieldName=fieldName;
							}
							
							var systemName = $("#comboxSystemName").combobox("getValue");
							if(systemName!=""){
								param.systemName=systemName;
							}
						},
						onLoadError : function(e) {
							$.messager.alert('错误', '<p>服务异常，'
									+ e.responseJSON.message
									+ '，请稍后重试或联系管理员!</p>', 'error');
						}
					});

			$("#datagrid").datagrid('getPager').pagination({
				displayMsg : '当前显示从 [{from}] 到 [{to}] 共[{total}]条记录'
			});
			$(".panel-tool-close, #instance_cancel").click(function(e) {
				$("body").css("overflow-x", "inherit")
			});

		});

function serviceLogExport() {
	var ifName = $('#txtIfName').val();
	var reqResult = $('#comboxReqResult').combobox('getValue');
	var startDateTime = $("#txtStartDateTime").datebox('getValue');
	var endDateTime = $("#txtEndDateTime").datebox('getValue');
	var data = '{"ifName":"' + ifName + '","reqResult":"' + reqResult + '" ,'
			+ '"startDateTime":"' + startDateTime + '","endDateTime":"'
			+ endDateTime + '"}';

	location.href = BASE_URL_API + '/serviceLogSearch/serviceLogExport?ifName='
			+ ifName + '&reqResult=' + reqResult + '&startDateTime='
			+ startDateTime + '&endDateTime=' + endDateTime;
}

function change(rowIndex){
	var row = $('#datagrid').datagrid('getRows')[parseInt(rowIndex, 10)];
	var interfaceId=row.id;
	var setting = row.isTrace;
	alert(setting);
	jsonStr = {interfaceId:interfaceId,setting:setting};
	$.ajax({
		url:'/api/serviceLogSearch/changeForIsSaveLogDesc' + '?v=' + Math.random(),
		dataType:'json',
		type:'get',
		contentType:"application/json",
		data: jsonStr,
		success:function(data){
			$.messager.alert('提示','<p>修改成功!</p>', 'info');
			$('#datagrid').datagrid('reload');
		},
		error: function() {
			$.messager.alert('错误','<p>服务异常，修改领域信息失败，请稍后重试或联系管理员!</p>', 'error');
		}
	});
}

// 查询
function search() {
	$('#datagrid').datagrid('reload');
}
function refresh() {
	$('#datagrid').datagrid('reload');
}

var loading_point = {
	timer : null,
	len : 3,
	count : 0
};
function loading() {
	if (loading_point.count < loading_point.len) {
		loading_point.count++;
		$("#progressbar_point").text($("#progressbar_point").text() + ".");
	} else {
		loading_point.count = 0;
		$("#progressbar_point").text("");
	}
}
